<template>
  <div id="app">
    <el-form ref="addGoodsForm" :model="g" label-width="80px">
      <el-form-item label="商品名称" prop="goodsName">
        <el-input v-model="g.goodsName"></el-input>
      </el-form-item>
      <el-form-item label="价格" prop="price">
        <el-input v-model="g.price" type="number"></el-input>
      </el-form-item>
      <el-form-item label="商品介绍" prop="description">
        <el-input v-model="g.description"></el-input>
      </el-form-item>
      <el-form-item label="生产日期" prop="createTime">
        <el-date-picker v-model="g.createTime"
                        type="datetime"
                        value-format="yyyy-MM-dd HH:mm:ss"
                        placeholder="请选择生产日期"
        ></el-date-picker>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="updateGoods">更新商品信息</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  name: "UpdateGoodsForm",
  data(){
    return{
      g:{}
    }
  },
  created() {
   this.axios.get("/GoodsManager/goods/"+this.$route.query.id).then(resp=>{
     this.g=resp.data.data;
   }).catch(error=>console.log(error))
  },
  methods:{
    updateGoods(){
      this.axios.put("/GoodsManager/goods/"+this.$route.query.id,this.g)
        .then(resp=>{
          if(resp.data.message=="success"&&resp.data.code==200){
            alert("更新成功");
            this.$router.push("/goods/show");
          }else {
            alert("更新失败");
          }
        })
    }
  }
}
</script>

<style scoped>

</style>
